<template>
  <div class="tools-list">
    <el-image src="/images/tools.png"></el-image>
    <!-- <div
      v-for="item in geometryShapes"
      :key="item.type"
      class="list-item"
      @click="handleClick(item)"
    >
      <div class="icon"></div>
      <div class="label">{{ item.name }}</div>
    </div> -->
  </div>
</template>
<script lang="ts" setup>
import {
  geometryShapes,
  GeometryShape,
  GeometryItem,
} from '@/graph/3d/config/shapes'
import { use3DEditorStore } from '@/store'

const editorStore = use3DEditorStore()
const { isCreating } = storeToRefs(editorStore)

const handleClick = (item: GeometryItem) => {
  if (isCreating.value) {
    editorStore.cancelCreate()
    return
  }
  editorStore.createShape(item)
}

const handleKeydown = (event: KeyboardEvent) => {
  // esc
  if (event.key === 'Escape') {
    if (isCreating.value) {
      editorStore.cancelCreate()
    }
  }
}

onBeforeMount(() => {
  document.addEventListener('keydown', handleKeydown)
})
onBeforeUnmount(() => {
  document.removeEventListener('keydown', handleKeydown)
})
</script>

<style lang="scss" scoped>
.tools-list {
  display: flex;
  flex-wrap: wrap;
  margin-top: 8px;

  .list-item {
    width: 50px;
    height: 50px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: 1px solid #ccc;
    border-radius: 6px;
    margin-right: 6px;
    margin-bottom: 6px;
    cursor: pointer;
    transition: all 0.3s;
    user-select: none;

    &:hover {
      background: #eee;
    }

    &:active {
      background: #ddd;
    }

    .icon {
      width: 20px;
      height: 20px;
      background: pink;
      border: 1px solid #ccc;
      border-radius: 6px;
      margin-bottom: 6px;
    }

    .label {
      font-size: 10px;
    }
  }
}
</style>
